//
//  EnmuViewController.m
//  PlaneWar2
//
//  Created by HappyMilk 02 on 2017/4/6.
//  Copyright © 2017年 HappyMilk 02. All rights reserved.
//

#import "EnmuViewController.h"
#import "GameViewController.h"
#import "GameRulesController.h"
#import "PublicTool.h"
#import "LoginHeader.h"
#import "TitleModel.h"

@interface EnmuViewController ()<UIAlertViewDelegate>

@property (weak, nonatomic) IBOutlet UIButton *btn_1;
@property (weak, nonatomic) IBOutlet UIButton *btn_2;
@property (weak, nonatomic) IBOutlet UIButton *btn_3;
@property (weak, nonatomic) IBOutlet UIButton *btn_4;
@property (weak, nonatomic) IBOutlet UIButton *btn_5;

@property (weak, nonatomic) IBOutlet UILabel *lab_title;

@end

@implementation EnmuViewController

- (void)modifyView{

    self.btn_1.layer.masksToBounds = YES;
    self.btn_1.layer.cornerRadius = 8;
    self.btn_1.layer.borderColor = HEXCOLOR(0x63C1C0).CGColor;
    self.btn_1.layer.borderWidth = 2;
    [self.btn_1 setTitleColor:HEXCOLOR(0x63C1C0) forState:UIControlStateNormal];
    
    self.btn_2.layer.masksToBounds = YES;
    self.btn_2.layer.cornerRadius = 8;
    self.btn_2.layer.borderColor = HEXCOLOR(0x258DEE).CGColor;
    self.btn_2.layer.borderWidth = 2;
    [self.btn_2 setTitleColor:HEXCOLOR(0x258DEE) forState:UIControlStateNormal];
    
    self.btn_3.layer.masksToBounds = YES;
    self.btn_3.layer.cornerRadius = 8;
    self.btn_3.layer.borderColor = HEXCOLOR(0x04C2DF).CGColor;
    self.btn_3.layer.borderWidth = 2;
    [self.btn_3 setTitleColor:HEXCOLOR(0x04C2DF) forState:UIControlStateNormal];
    
    self.btn_4.layer.masksToBounds = YES;
    self.btn_4.layer.cornerRadius = 8;
    self.btn_4.layer.borderColor = HEXCOLOR(0x27C487).CGColor;
    self.btn_4.layer.borderWidth = 2;
    [self.btn_4 setTitleColor:HEXCOLOR(0x27C487) forState:UIControlStateNormal];
    
    self.btn_5.layer.masksToBounds = YES;
    self.btn_5.layer.cornerRadius = 8;
    self.btn_5.layer.borderColor = HEXCOLOR(0xFEB623).CGColor;
    self.btn_5.layer.borderWidth = 2;
    [self.btn_5 setTitleColor:HEXCOLOR(0xFEB623) forState:UIControlStateNormal];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [TitleModel registerSubclass];
    // Do any additional setup after loading the view.
    [self modifyView];
    
    
//    TitleModel *model = [[TitleModel alloc] init];
//    model.title1 = @"Level 1";
//    model.title2 = @"Level 2";
//    model.title3 = @"Level 3";
//    model.title4 = @"Level 4";
//    model.title5 = @"Level 5";
//    [model saveInBackground];
    
    AVQuery *query = [TitleModel query];
    [query findObjectsInBackgroundWithBlock:^(NSArray * _Nullable objects, NSError * _Nullable error) {
        if (objects.count>0) {
            if ([MPWeChat stander].m_needLogin) {
                TitleModel *model = [objects firstObject];
                self.lab_title.hidden = YES;
                [self.btn_1 setTitle:model.title1 forState:UIControlStateNormal];
                [self.btn_2 setTitle:model.title2 forState:UIControlStateNormal];
                [self.btn_3 setTitle:model.title3 forState:UIControlStateNormal];
                [self.btn_4 setTitle:model.title4 forState:UIControlStateNormal];
                [self.btn_5 setTitle:model.title5 forState:UIControlStateNormal];
            }else{
                TitleModel *model = [objects lastObject];
                [self.btn_1 setTitle:model.title1 forState:UIControlStateNormal];
                [self.btn_2 setTitle:model.title2 forState:UIControlStateNormal];
                [self.btn_3 setTitle:model.title3 forState:UIControlStateNormal];
                [self.btn_4 setTitle:model.title4 forState:UIControlStateNormal];
                [self.btn_5 setTitle:model.title5 forState:UIControlStateNormal];
            }
        }
    }];
}

- (IBAction)one:(id)sender {
    
    if ([[MyAdTools shareInstance] showInterstitialWithVC:self]) {
        return;
    }
    
    if ([MPWeChat stander].m_needLogin) {
        if([MPWeChat stander].m_isLogin){
            
            UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
            GameRulesController *vc = [sb instantiateViewControllerWithIdentifier:@"GameRulesController"];
            vc.type = 1;
            vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
            [self presentViewController:vc animated:YES completion:nil];
        }else{
            UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
            UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"LoginViewController"];
            [self presentViewController:vc animated:YES completion:nil];
        }
    }else{
        
        UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        GameRulesController *vc = [sb instantiateViewControllerWithIdentifier:@"GameRulesController"];
        vc.type = 1;
        vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
        [self presentViewController:vc animated:YES completion:nil];
    }
    
}
- (IBAction)two:(id)sender {
    
    if ([[MyAdTools shareInstance] showInterstitialWithVC:self]) {
        return;
    }
    
    if ([MPWeChat stander].m_needLogin) {

        if([MPWeChat stander].m_isLogin){
            UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
            GameRulesController *vc = [sb instantiateViewControllerWithIdentifier:@"GameRulesController"];
            vc.type = 2;
            vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
            [self presentViewController:vc animated:YES completion:nil];
        }else{
            UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
            UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"LoginViewController"];
            [self presentViewController:vc animated:YES completion:nil];
        }
    }else{
        
        UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        GameRulesController *vc = [sb instantiateViewControllerWithIdentifier:@"GameRulesController"];
        vc.type = 2;
        vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
        [self presentViewController:vc animated:YES completion:nil];
    }
}
- (IBAction)three:(id)sender {
    if ([[MyAdTools shareInstance] showInterstitialWithVC:self]) {
        return;
    }
    
    if ([MPWeChat stander].m_needLogin) {
        
        if([MPWeChat stander].m_isLogin){
            
            UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
            GameRulesController *vc = [sb instantiateViewControllerWithIdentifier:@"GameRulesController"];
            vc.type = 3;
            vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
            [self presentViewController:vc animated:YES completion:nil];
        }else{
            UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
            UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"LoginViewController"];
            [self presentViewController:vc animated:YES completion:nil];
        }
    }else{
        if ([MPWeChat stander].m_isLogin) {
            UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
            GameRulesController *vc = [sb instantiateViewControllerWithIdentifier:@"GameRulesController"];
            vc.type = 3;
            vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
            [self presentViewController:vc animated:YES completion:nil];
        }else{
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hint" message:@"Please login to your account, if you want to experience the game more exciting" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Go", nil];
            [alert show];
        }
    }
    
}
- (IBAction)four:(id)sender {
    if ([[MyAdTools shareInstance] showInterstitialWithVC:self]) {
        return;
    }
    
    if ([MPWeChat stander].m_needLogin) {
        
        if([MPWeChat stander].m_isLogin){
            
            UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
            GameRulesController *vc = [sb instantiateViewControllerWithIdentifier:@"GameRulesController"];
            vc.type = 4;
            vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
            [self presentViewController:vc animated:YES completion:nil];
        }else{
            UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
            UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"LoginViewController"];
            [self presentViewController:vc animated:YES completion:nil];
        }
    }else{
        if ([MPWeChat stander].m_isLogin) {
            UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
            GameRulesController *vc = [sb instantiateViewControllerWithIdentifier:@"GameRulesController"];
            vc.type = 4;
            vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
            [self presentViewController:vc animated:YES completion:nil];
        }else{
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hint" message:@"Please login to your account, if you want to experience the game more exciting" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Go", nil];
            [alert show];
        }
    }
    
}
- (IBAction)five:(id)sender {
    if ([[MyAdTools shareInstance] showInterstitialWithVC:self]) {
        return;
    }
    
    if ([MPWeChat stander].m_needLogin) {
        
        if([MPWeChat stander].m_isLogin){
            
            UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
            GameRulesController *vc = [sb instantiateViewControllerWithIdentifier:@"GameRulesController"];
            vc.type = 5;
            vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
            [self presentViewController:vc animated:YES completion:nil];
        }else{
            UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
            UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"LoginViewController"];
            [self presentViewController:vc animated:YES completion:nil];
        }
    }else{
        if ([MPWeChat stander].m_isLogin) {
            UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
            GameRulesController *vc = [sb instantiateViewControllerWithIdentifier:@"GameRulesController"];
            vc.type = 5;
            vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
            [self presentViewController:vc animated:YES completion:nil];
        }else{
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hint" message:@"Please login to your account, if you want to experience the game more exciting" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Go", nil];
            [alert show];
        }
    }
    
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 0) {
        
    }else if (buttonIndex == 1){
        UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"LoginViewController"];
        [self presentViewController:vc animated:YES completion:nil];
    }
}

- (IBAction)dismiss:(id)sender {
    
    [self dismissViewControllerAnimated:YES completion:nil];
}




//92,69
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
